<template>
	<div>
		sdfsdfdsf
		{{msg}}
		<vue-baberrage
		:isShow= "barrageIsShow"
		:barrageList = "barrageList"
		:loop = "barrageLoop"
		:boxHeight = "barrageHeight"
		>
		</vue-baberrage>
		<div class="btnBox">
			<div class="bottom"><button @click="addToList">sdfsdf</button></div>
			<div class="bottom"><button @click="getBless">getBless</button></div>
		</div>
		
		<div class="signList">
			<ul>
				<li v-for="(value,key) in sign_lists" :key="key">
					<p><img :src="value.avatarUrl" alt=""></p>
					<p>{{value.nickName}}</p>
				</li>
			</ul>
		</div>
	</div>
	
</template>
<script>
import Vue from 'vue'
import {get,post} from '@/utils/index';
import vueBaberrage from 'vue-baberrage'
import {getBless,getActDetails} from '@/utils/api';
Vue.use(vueBaberrage);
	export default {
		data() {
			return {
				msg: 'Hello vue-baberrage',
				barrageIsShow: true,
				currentId : 0,
				barrageLoop: true,
				barrageHeight:800,
				barrageList: [],
				sign_lists:[]
			}
		},
		onLoad() {
			this.init()
		},
		
		methods: {
			init(){
				this.getBless()
				this.getSignList()
				let that = this
				uni.connectSocket({
					url: 'wss://wx.igiky.cn/wss'
				});
				uni.onSocketMessage(function (res) {
					let obj = JSON.parse(res.data)
					console.log('收到服务器内容：' , obj);
					if(obj.type == 'signList'){
						that.sign_lists.unshift(obj.data)
					}else if(obj.type == 'bless'){
						that.barrageList.push(obj.data)
					}
					
				});
			},
			getBless(){
				get(getBless,{
					aid:3
				}, true)
				.then((res)=>{
					let arr=[]
					let ext={
						time:5,
						type:0
					}
					for(var datas of res){  
						// console.log(2,datas)  
						Object.assign(datas,ext);
						arr.push(datas)
					}
					// console.log(arr)
					// Object.assign(this.barrageList,res.data);
					this.barrageList = arr
					
				})
			},
			getSignList(){
				get(getActDetails,{
					aid:3
				}, true)
				.then((res)=>{
					// this.sign_lists = res.signList
					this.sign_lists = res.data.signList

					console.log(98,res)
				})
			},
			addToList (){
				this.barrageList.push({
					id: ++this.currentId,
					avatar: "./static/avatar.jpg",
					msg: this.msg,
					// barrageStyle: "normal",
					time: 5,
					type: 0,
					position: 'top'
				});
			}
		}
	}
</script>

<style scoped lang="scss">
@import './style.scss';

</style>
